<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>

		<script src="../libs/jquery.3.6.0.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>


		<h1></h1>



		<script type="text/javascript">
			function find(index) {

				let a = [];

				for (var i = 0; i < 100000; i++) {
					a[i] = i;

				}

				return (
					function(index) {
						console.log(`找到 ${a[index]} 的时间为：`);

					}
				);


			}



			// console.time();
			// find(60);
			// console.timeEnd();



			// console.time();
			// find(60);
			// console.timeEnd();

			console.log('=============================================')

			// 生成闭包
			// const closure = find();

			// console.time();
			// closure(60);
			// console.timeEnd();


			// console.time();
			// closure(60);
			// console.timeEnd();
		</script>


		<!-- 1. 闭包 优化处理效率 
		 
			 2. 设计模式   && 功能（防抖  /节流） 
			 
			 
			 
			 
			 
		 -->

		<script type="text/javascript">
			// 模块设计模式 
			const UICtrl = (function() {


				let text = "闭包是JS的精髓";

				const changeText = () => {
					const element = document.querySelector("h1");
					element.textContent = text;
				}


				return {
					callChangeText: () => {
						changeText()
					}
				}
			})();


			UICtrl.callChangeText();
		</script>
	</body>
</html>
